// pages/expert/expertDetail.js

const defaultSettings = require('../../config/defaultSettings')
import {changeProfilePicture} from '../../api/login'
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    defaultSettings,
    primaryColor:defaultSettings.primaryColor,
    emp:app.globalData.appInfo.emp,
    loading:false,
    formAttributes:[
      // {field:'profilePicture',label:'头像',component:'imageUp',required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}],maxCount:1},
      {field:'empName',label:'姓名',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'accountNo',label:'账号',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'empNo',label:'工号',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'empPhone',label:'手机号',component:'input',readonly:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}]},
      {field:'empType',label:'类别',component:'select',disabled:true,required:false,isShowLabel:true,border:true,clean:true,rules: [{required: false, message: '不能为空'}],dictCode:defaultSettings.dictCodes.empType},

    
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: "个人信息",
    })
    this.setData({emp:getApp().globalData.appInfo.emp})
  },
  onLoginout(){
    wx.clearStorage({
      success: function(res) {
        wx.reLaunch({
          url: '/pages/login/login',
        })
      },
      fail: function(res) {
        console.log('退出失败');
      }
    });
  },
  onChange(e){
    const field = e["detail"]["field"]
    const val = e["detail"]["val"]
    if(val && field==='profilePicture'){
      //头像修改
      changeProfilePicture({accountNo:this.data.emp.accountNo,profilePicture:val}).then(res=>{
        if(res.success){
          wx.showToast({title: '操作成功',icon: 'success'})
          app.globalData.appInfo.emp.profilePicture = val
        }else{
          wx.showToast({icon:"none",title: res.message})
        }
      })

    }
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})